<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.Date,com.padgett.resourcemanagement.util.DateUtil" %>
<!DOCTYPE HTML>
<html>
<head>
<%
String clientId=(String)request.getAttribute("clientId");
String clientName=(String)request.getAttribute("clientName");
%>
<title>Client - <%=clientName %></title>
<%@include file="/WEB-INF/css.jsp" %>
<%@include file="/WEB-INF/javascript.jsp" %>
<style>
.BusinessClientContainer{
	width:1024px;
	height:400px;
	padding:10px;
	margin:10px;
	border:1px solid #a3a3a3;
}
</style>
<script>
$(document).ready(function(){
	$('#DeleteServiceDialog').dialog({
		resizable:false,
		autoOpen:false,
		height:240,
		width:800,
		modal:true,
		buttons:{
			"Delete":function(){
				//TODO Call AjaxDeleteService
				$.ajax({
					url:"/AjaxDeleteService",
					type:"POST",
					dataType:"json",
					data:{
						serviceId:$('#serviceId').val()
					},
					success:function(data,status,xhr){
						window.location.href='/services.jsp?clientId=<%=clientId %>&clientName=<%=clientName%>';
					},
					error:function(xhr,status,error){
						alert("error:"+error);
					}
				});
			},
			Cancel:function(){
				$(this).dialog("close");
			}
		}
	});
	$('#CompleteServiceButton').button().click(function(){
		$.ajax({
			url:"/AjaxCompleteService",
			type:"POST",
			dataType:"json",
			data:{
				serviceId:$('#serviceId').val()
			},
			success:function(data,status,xhr){
				window.location.href='/GetService?serviceId='+$('#serviceId').val()+'&clientId='+$('#clientId').val()+'&clientName='+$('#clientName').val();
			},
			error:function(xhr,status,error){
				alert("error:"+error);
			}
		});
	});
	$('#ClientServicesButton').button().click(function(){
		window.location.href='/services.jsp?clientId=<%=clientId %>&clientName=<%=clientName%>';
	});
	$('#EditServiceButton').button().click(function(){
		$('#ServiceDialog').dialog('open');
	});
	$('#DeleteServiceButton').button().click(function(){
		$('#DeleteServiceDialog').dialog("open");
	});
});
</script>
</head>
<body>
<%@include file="/WEB-INF/clientnavigation.jsp" %>
<div class="Container" style="margin-bottom:10px;margin-top:-20px;">
	<h1>SERVICE DETAIL</h1>
<div id="ActionsContainer" style="float:left;width:100%;margin:0 0 10px 18px">
<button id="ClientServicesButton">Back to Client Services</button>
<%
Date completedDate=(Date)request.getAttribute("CompletedDate");
if(completedDate==null){
%>
<button id="CompleteServiceButton">Complete</button>
<%
}
%>
<button id="EditServiceButton" style="margin-left:50px;">Edit</button>
<button id="DeleteServiceButton">Delete</button><div id="DeleteServiceDialog" title="Delete Service">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>This item will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
</div><br/>
<%@include file="/WEB-INF/servicedialog.jsp" %>
<div class="ClientContainer">
<table>
	<tr>
		<td>Type:</td><td><input id="clientId" name="clientId" type="hidden" value="<%=request.getAttribute("clientId") %>"/>
		<input id="clientName" name="clientName" type="hidden" value="<%=request.getAttribute("clientName") %>"/>
		<input id="serviceId" name="serviceId" type="hidden" value="<%=request.getAttribute("serviceId") %>"/><%=request.getAttribute("Type") %></td>
	</tr>
	<tr>
		<td>Fee:</td><td><%=(request.getAttribute("Fee")!=null?"$"+request.getAttribute("Fee"):"") %></td>
	</tr>
	<tr>
		<td>Billable:</td><td><%=(request.getAttribute("Billable")!=null&&((Boolean)request.getAttribute("Billable"))==Boolean.TRUE?"Yes":"No") %></td>
	</tr>
	<%
		Date dueDate=(Date)request.getAttribute("DueDate");
		if(dueDate!=null){
			out.print("<tr><td>Due Date:</td><td>"+DateUtil.formatDate(dueDate,DateUtil.LONG_DATE_FORMAT)+"</td></tr>");
		}
	%>
	<tr>
		<td>Accountant:</td><td>
		<%=(request.getAttribute("AccountantName")!=null?request.getAttribute("AccountantName"):"") %></td>
	</tr>
	<tr>
		<td>Note:</td>
		<td>
			<%=(request.getAttribute("Note")!=null?request.getAttribute("Note"):"") %>
		</td>
	</tr>
	<%
		if(completedDate!=null){
			out.print("<tr><td>Completed Date:</td><td>"+DateUtil.formatDate(completedDate,DateUtil.LONG_DATE_FORMAT)+"</td></tr>");
		}
	%>
	<%
		String completedBy=(String)request.getAttribute("CompletedBy");
		if(completedBy!=null){
			out.print("<tr><td>Completed By:</td><td>"+completedBy+"</td></tr>");
		}
	%>
</table>
</div>
</div>
</body>
</html>